package com.codinghero.example.daily;

import java.util.Random;

public class ProPearlProb1 {
	
	private static int BITESPERWORD = 32;
	private static int SHIFT = 5;
	private static int MASK = 0x1f;
	private static int N = 10000000;
	
	private static int[] a = new int[1 + N / BITESPERWORD];
	
	public static void main(String[] args) {
		for (int i = 0; i < N; i++) {
			clr(i);
		}
		System.out.println("input");
		for (int i = 0; i < 10; i++) {
			int rnd = new Random().nextInt(N);
			set(rnd);
			System.out.println(rnd);
		}
		System.out.println("output");
		for (int i = 0; i < N; i++) {
			if (test(i) != 0) {
				System.out.println(i + "," + get(i) + "," + test(i));
			}
		}
	}
	
	private static void set(int i) {
		a[i >> SHIFT] |= (1 << (i & MASK));
	}
	
	private static int get(int i) {
		return a[i >> SHIFT];
	}
	
	private static void clr(int i) {
		a[i >> SHIFT] &= ~(1 << (i & MASK));
	}
	
	private static int test(int i) {
		return a[i >> SHIFT] & (1 << (i & MASK));
	}
}
